package com.tpp.controller;

import com.tpp.pojo.Comment;
import com.tpp.pojo.CommentReply;
import com.tpp.pojo.baseVo.BaseResult;
import com.tpp.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService commentService;
    //评论
    @RequestMapping(value = "/addComments",method = RequestMethod.POST)
    public BaseResult addComment(@RequestBody Comment comment) {
        System.out.println(comment);

        BaseResult baseResult = commentService.addComment(comment);
        return baseResult;
    }
    //回复评论
    @RequestMapping("/addCommentReply")
    public BaseResult addCommentReply(@RequestBody CommentReply commentReply){
        BaseResult baseResult = commentService.addCommentReply(commentReply);
        return  baseResult;
    }
    //根据电影id查询到评论，评论查询到回复评论
    @RequestMapping("/findAllComment/{mid}")
    public BaseResult findAllComment(@PathVariable Integer mid){
        return commentService.findAllComment(mid);

    }
    //删除电影评论
    @RequestMapping(value = "/deleteComment",method = RequestMethod.GET)
    public BaseResult deleteComment(@RequestParam("cid")Integer cid,@RequestParam("uid") Integer uid){
        BaseResult baseResult = commentService.deleteComment(cid,uid);
        return baseResult;
    }
    //删除回复评论
    @RequestMapping(value = "/deleteCommentReply",method = RequestMethod.GET)
    public BaseResult deleteCommentReply(@RequestParam("rid")Integer rid,@RequestParam("cpid") Integer cpid){
        BaseResult baseResult = commentService.deleteCommentReply(rid,cpid);
        return baseResult;
    }
}
